package correlation;

import java.util.LinkedList;
import java.util.List;

import dom.HyperAlert;

public class HyperAlertCorrelationNode {
	HyperAlert hAlert;
	List<HyperAlertCorrelationNode> prerequisiteNodes;
	List<HyperAlertCorrelationNode> consequenceNodes;

	public HyperAlertCorrelationNode(HyperAlert newHyperAlert){
		hAlert = newHyperAlert;
		prerequisiteNodes = new LinkedList<HyperAlertCorrelationNode>();
		consequenceNodes = new LinkedList<HyperAlertCorrelationNode>();
	}
	public void addPrerequisiteNode(HyperAlertCorrelationNode hacn){
		if(hacn != null && !prerequisiteNodes.contains(hacn)){
			prerequisiteNodes.add(hacn);
		}
	}
	public void addConsequenceNode(HyperAlertCorrelationNode hacn){
		if(hacn != null && !consequenceNodes.contains(hacn)){
			consequenceNodes.add(hacn);
		}
	}
	public HyperAlert getAlert(){
		return hAlert;
	}
	
	/**
	 * Simplifies retrieving the name of the hyper alert type inside the node
	 * @return
	 */
	public String getHyperAlertTypeName(){
		if(hAlert != null && hAlert.getType() != null && hAlert.getType().getName() != null){
			return hAlert.getType().getName();
		}
		return "";
	}
	
	public List<HyperAlertCorrelationNode> getPrerequisiteNodes() {
		return prerequisiteNodes;
	}

	public List<HyperAlertCorrelationNode> getConsequenceNodes() {
		return consequenceNodes;
	}
	
	public boolean preparesFor(HyperAlertCorrelationNode nodeBeingPreparedFor){
		return false;
	}
	
	public boolean isARootNode(){
		return (this.prerequisiteNodes == null || this.prerequisiteNodes.isEmpty());
	}
	
}
